package org.example.day02;

/**
 * 第一章节1.10.4:看谁运行的快
 */
public class MyThread11 extends Thread{
    public static void main(String[] args) {
        try {
            ThreadA a = new ThreadA();
            a.setPriority(Thread.NORM_PRIORITY - 3);
            a.start();
            ThreadB b = new ThreadB();
            b.setPriority(Thread.NORM_PRIORITY + 3);
            b.start();
            Thread.sleep(1000);
            a.stop();
            b.stop();
            System.out.println("a = " + a.getCount());
            System.out.println("b = " + b.getCount());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class ThreadA extends Thread{
    private int count = 0;

    public int getCount(){
        return count;
    }

    @Override
    public void run() {
        while(true){
            count++;
        }
    }
}

class ThreadB extends Thread{
    private int count = 0;

    public int getCount(){
        return count;
    }

    @Override
    public void run() {
        while(true){
            count++;
        }
    }
}

//b优先级高，获取cpu机会多一些
//a = 393770428
//b = 515219312